#include<bits/stdc++.h>
using namespace std;
int qian[10010],s,q,x,y,z;
int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
void search(int v)
{
	int ans;
	if(qian[v]==1) 
	{
		cout<<0<<endl;
		return;
	}
	else
	{
		for(int i=v; i>=1; --i)
		{
			if(qian[i]==1)
			{
				cout<<0<<endl;
				return;
			}
			else if(qian[i]==-1) 
			{
				ans+=v-i;
				break;
			}
			if(i==1)
			{
				cout<<"INF"<<endl;
				return;
			}
		}
		for(int i=v+1; i<=s; ++i)
		{
			if(qian[i]==1)
			{
				ans+=i-v;
				break;
			}
			if(i==s)
			{
				cout<<"INF"<<endl;
				return;
			}
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	freopen("explore.in","r",stdin);
	freopen("explore.out","w",stdout);
	s=read(),q=read();
	for(int i=1; i<=q; ++i)
	{
		x=read();
		if(x==1) y=read(),z=read(),qian[y]=1,qian[z+1]=-1;
		else if(x==2) y=read(),z=read(),qian[y]=-1,qian[z+1]=1;
		else y=read(),search(y);
	}
}
